package com.gj.server;

import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.channel.ChannelInitializer;
import io.netty.channel.socket.SocketChannel;
import io.netty.handler.codec.DelimiterBasedFrameDecoder;

/**
 * @author Gjing
 *
 * netty服务初始化器
 **/
public class ServerChannelInitializer extends ChannelInitializer<SocketChannel> {
    @Override
    protected void initChannel(SocketChannel socketChannel) throws Exception {
        //添加编解码

//        socketChannel.pipeline().addLast("decoder", new StringDecoder());
//        socketChannel.pipeline().addLast("encoder", new ByteArrayEncoder());

        byte[] bytes = {(byte)0xaa};
        ByteBuf delimiter = Unpooled.copiedBuffer(bytes);
        socketChannel.pipeline().addLast(new DelimiterBasedFrameDecoder(1024, delimiter));
//        socketChannel.pipeline().addLast(new FixedLengthFrameDecoder(5));

        socketChannel.pipeline().addLast(new MyByteToGyroDecoder());

//        socketChannel.pipeline().addLast("decoder", new DlhFrameDecoder());
//        socketChannel.pipeline().addLast("encoder", new DlhFrameEncoder());


        socketChannel.pipeline().addLast(new MyServerHandler());
    }
}
